<template>
	<view>
		<view @click="add">
			<uni-fab>扫码</uni-fab>
		</view>
		<view class="uni-container">			
			<zhTable :hander_list='hander_list' :table_list='inspList' :height="1800" :label_height="160" scroll_y
					:indicator_type='2'>
					<template v-slot:row="{row,index}">
						<view class="item" @click="info(row)" style="color:lightskyblue;text-decoration: underline;">
							{{row.applyCode}}
						</view>
						<view class="item">
							{{row.applyContent}}
						</view>
						<view class="item">
							<view v-if="row.applyStatus==-1" class="style1">驳回</view>
							<view v-if="row.applyStatus==0" class="style2">待确认</view>
							<view v-if="row.applyStatus==1" class="style3">待外发</view>
							<view v-if="row.applyStatus==2" class="style4">待维修</view>
							<view v-if="row.applyStatus==3" class="style5">已完成</view>
						</view>
						
						<view class="item">
							{{row.createTime}}
						</view>
						<view class="item">
							<view v-if="row.applyStatus==0" v-hasPermi="['sc:deviceMaintenance:add']">
								<view @click="edit(row)" class="action2">
									<uni-icons type="compose" size="20" color="#b5e271;"></uni-icons>
									编辑
								</view>
							</view>
							<view v-else>
								<view @click="info(row)" class="action1">
									<uni-icons type="eye" size="20" color="#80c2ff"></uni-icons>
									详情
								</view>
							</view>
							<view v-if="row.applyStatus==0" v-hasPermi="['sc:deviceMaintenance:review']">
								<view @click="review(row)" class="action3">
									<uni-icons type="checkbox" size="20" color="#f56c6c;"></uni-icons>
									审批
								</view>
							</view>
							<view v-else-if="row.applyStatus==2" v-hasPermi="['sc:deviceMaintenance:feedback']">
								<view @click="apply(row)" class="action2">
									<uni-icons type="wallet" size="20" color="#b5e271;"></uni-icons>增加维修单
								</view>
							</view>
							<view v-if="row.applyStatus==1" v-hasPermi="['sc:deviceMaintenance:out']">
								<view @click="toTrans(row)" class="action3">
									<uni-icons type="paperplane" size="20" color="#f56c6c;"></uni-icons>
									外发
								</view>			
							</view>
						</view>
					</template>
				</zhTable>
			
			<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total" @change="change" /></view>
		</view>
	
	</view>
</template>

<script>
	import { getTaskList, trans } from '@/common/api/repair'
	import zhTable from '@/components/zh-table/zhTable.vue'
	export default {
		components: {
			zhTable
		},
		data() {
			return {
				hander_list: [{
						id: 1,
						name: '维修单编号'
					},
					{
						id: 2,
						name: '维修内容'
					},
					{
						id: 3,
						name: '申请状态'
					},
					{
						id: 4,
						name: '创建时间'
					},
					{
						id: 5,
						name: '操作'
					}
				],
				inspList: [],
				// 每页数据量
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				loading: false
			}
		},
		onShow() {
			this.getData(1)
		},
		methods: {
			// 分页触发
			change(e) {
				this.getData(e.current)
			},
			// 获取数据
			getData(pageCurrent, value = '') {
				this.loading = true
				this.pageCurrent = pageCurrent
				getTaskList({
					pageSize: this.pageSize,
					pageNum: pageCurrent,
					value: value
				}).then(res => {
					console.log(res, 'res')
					this.inspList = res.data.rows
					this.total = res.data.total
					this.loading = false
				})
			},
			/** 详情按钮操作 */
			info(row) {
				// 页面跳转
				uni.navigateTo({
				  url: `/pages/repaire/info?id=${row.id}`
				});
			},
			/** 修改按钮操作 */
			edit(row) {
				// 页面跳转
				uni.navigateTo({
				  url: `/pages/repaire/edit?id=${row.id}`
				});
			},
			add() {
				uni.navigateTo({
					url: '/pages/repaire/edit'
				})
			},
			review(row) {
				// 页面跳转
				uni.navigateTo({
				  url: `/pages/repaire/review?id=${row.id}`
				});
			},
			apply(row) {
				uni.navigateTo({
				  url: `/pages/repaire/apply?id=${row.id}`
				});
			},
			toTrans(row) {
				uni.showModal({
					content: '是否确认外发?',
					success: function (res) {
						if (res.confirm) {
							this.loading = true
							return handelTrans(row.id)
						}
					}
				});
			},
			handelTrans() {
				trans({
				    status: true,
				    applyId: row.id
				}).then(res => {
					this.loading = false
					if (res.respCode === '0000') {
						uni.showToast({
						  title: '外发成功',
						  duration: 2000
						});
					  this.getData(this.pageCurrent)
					}
				})
			},
			/** 删除按钮操作 */
			del(row) {
			  const that = this
			  uni.showModal({
			  	content: '是否确认删除?',
			  	success: function (res) {
			  		if (res.confirm) {
			  			that.loading = true
			  			return handelDel(row.id)
			  		}
			  	}
			  });
			},
			handelDel(id) {
				if (response.respCode === '0000') {
				  this.getList()
				  uni.showToast({
				  	title: '删除成功',
				  	duration: 2000
				  });
				} else {
				  this.msgError(response.respMsg)
				}
			}
		}
	}
</script>


<style>
	.item {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.style1 {
		background-color: #fef0f0;
		border: 1px solid #faecd8;
		color: #e6a23c;
		font-size: 12px;
		padding: 2px;
		border-radius: 5px;
	}

	.style2 {
		background-color: #fdf6ec;
		border: 1px solid #fde2e2;
		color: #f56c6c;
		font-size: 12px;
		padding: 2px;
		border-radius: 5px;
	}

	.style3 {
		background-color: #f4f4f5;
		border: 1px solid #e9e9eb;
		color: #909399;
		font-size: 12px;
		padding: 2px;
		border-radius: 5px;
	}

	.style4 {
		background-color: #ecf5ff;
		border: 1px solid #d9ecff;
		color: #409eff;
		font-size: 12px;
		padding: 2px;
		border-radius: 5px;
	}

	.style5 {
		background-color: #f0f9eb;
		border: 1px solid #e1f3d8;
		color: #67c23a;
		font-size: 12px;
		padding: 2px;
		border-radius: 5px;
	}

	.action1 {
		color: #80c2ff;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.action2 {
		color: #b5e271;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.action3 {
		color: #f56c6c;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
</style>